package com.jack.leetcode.eachProblem07;

/**
 * Created by zhang_j on 2020/7/20
 */
public class 两数之和2 {

    public int[] twoSum(int[] numbers, int target) {
        if(numbers == null){
            return null;
        }
        int n = numbers.length;

        int i = 0,j = n-1;
        while(i < j){
            int sum = numbers[i] + numbers[j];
            if(sum == target){
                return new int[]{i+1,j+1};
            }else if (sum > target){
                j--;
            }else{
                i++;
            }
        }
        return null;
    }
}
